home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / apb17.zip / MOUSE.BAS < prev    next >
BASIC Source File  |  1990-12-20  |  4KB  |  151 lines

  1.  
  2.     ' Include file of Subprograms and Functions for using a
  3.     ' Microsoft compatible mouse (Tested with Logitech)
  4.     ' This include file uses 2 assembler files: Int.com and MouseI.com
  5.  
  6.     ' Subprogram to do software interrupts
  7. Sub DoInt IntNo%,Reg%(1) External "Int.Com"
  8.     ' Assign a trap # to a mouse event
  9. Sub SetMouseTrap CondMask%,TrapNo% External "MouseI.Com"
  10.     ' Reset the mouse trap
  11. Sub ResetMouseTrap External "" 3
  12.     ' Return information after a mouse interrupt
  13. Sub GetMouseInfo CondMask%,Hpos%,Vpos%,Buttons% External "" 6
  14.     ' Constants for Condition mask. OR these together to trap
  15.     ' multiple mouse events
  16. Const Ms.Pos%=1        ' Mouse position changed
  17. Const Ms.LeftDn%=2    ' Left button pressed
  18. Const Ms.LeftUp%=4    ' Left button released
  19. Const Ms.RightDn%=8    ' Right button pressed
  20. Const Ms.RightUp%=16    ' Right button released
  21. Const Ms.MiddleUp%=32    ' Middle button pressed
  22. Const Ms.MiddleDn%=64    ' Middle button released
  23.  
  24.     ' Function to peek an integer
  25. Def PeekWord%(Offset%)
  26.     PeekWord%=Peek(Offset%)+(Peek(Offset%+1) Shl 8)
  27. End Def
  28.  
  29.     ' ----------- Start of Mouse functions ----------------------
  30.  
  31.     ' Array used when for holding machine registers
  32.     ' when doing interrupts to the mouse software
  33. Dim MouseRegs%(0 to 9)
  34.  
  35.     ' Constants for accessing the above array
  36. Const Flags=0
  37. Const Ax=1
  38. Const Bx=2
  39. Const Cx=3
  40. Const Dx=4
  41. Const Si=5
  42. Const Di=6
  43. Const Bp=7
  44. Const Ds=8
  45. Const Es=9
  46.  
  47.     ' Check if the Mouse is available and
  48.     ' initialize.
  49.     ' Returns:
  50.     '    0 = Not available. Don't do any mouse functions if
  51.     '        if this Def returns zero.
  52.     '    1 = Mouse available.
  53. Def MouseInit%()
  54.     Local MouseSeg%,MouseOff%
  55.     Def Seg=0
  56.     MouseOff%=PeekWord%(&h33*4+2)
  57.     MouseSeg%=PeekWord%(&h33*4)
  58.     MouseInit%=1        ' Assume it's there
  59.     If MouseSeg%=0 And MouseOff%=0 then
  60.         MouseInit%=0    ' INT vector is zero
  61.     Else
  62.         Def Seg=MouseSeg%
  63.         If Peek(MouseOff%)=&hcf Then
  64.             MouseInit%=0    ' INT vector points to IRET
  65.         Else
  66.             MouseRegs%(Ax)=0
  67.             DoInt &h33,MouseRegs%()
  68.             If MouseRegs%(Ax)=0 Then
  69.                 MouseInit%=0
  70.             End If
  71.         End If
  72.     End If
  73. End Def
  74.  
  75.     ' Show the mouse cursor
  76. Sub MouseShow
  77.     MouseRegs%(Ax)=1
  78.     DoInt &h33,MouseRegs%()
  79. End Sub
  80.  
  81.     ' Hide the mouse cursor
  82. Sub MouseHide
  83.     MouseRegs%(Ax)=2
  84.     DoInt &h33,MouseRegs%()
  85. End Sub
  86.  
  87.     ' Set mouse cursor to a position on the screen
  88. Sub MouseSet HPos%, VPos%
  89.     MouseRegs%(Cx)=HPos%
  90.     MouseRegs%(Dx)=VPos%
  91.     MouseRegs%(Ax)=4
  92.     DoInt &h33,MouseRegs%()
  93. End Sub
  94.  
  95.     ' Return mouse status
  96.     ' Be sure to pass actual variables to this subprogram, not expressions
  97. Sub MouseStatus Hpos%, Vpos%, Buttons%
  98.     MouseRegs%(Ax)=3
  99.     DoInt &h33,MouseRegs%()
  100.     Hpos%=MouseRegs%(Cx)
  101.     Vpos%=MouseRegs%(Dx)
  102.     Buttons%=MouseRegs%(Bx)
  103. End Sub
  104.  
  105.     ' Return the distance mouse moved since last call
  106. Sub MouseMotion Hpos%, Vpos%
  107.     MouseRegs%(Ax)=11
  108.     DoInt &h33,MouseRegs%()
  109.     Hpos%=MouseRegs%(Cx)
  110.     Vpos%=MouseRegs%(Dx)
  111. End Sub
  112.  
  113.     ' Define the region to restrict the mouse
  114.     ' UpH%=Upper left horizontal pos of region
  115.     ' UpV%=Upper left vertical    "  "    "
  116.     ' LowerH%=Lower right horizontal pos of region
  117.     ' LowerV%=Lower right vertical    "  "    "
  118.     '  NOTE: The coordinates of the region is in pixels, NOT character
  119.     '  coordinates. ROW=MousePosV/8+1, COL=MousePosH/8+1
  120.     '  MousePosV=(ROW-1)*8, MousePosH=(COL-1)*8
  121. Sub MouseBounds UpV%,UpH%,LowerV%,LowerH%
  122.     MouseRegs%(Cx)=UpH%
  123.     MouseRegs%(Dx)=LowerH%
  124.     MouseRegs%(Ax)=7
  125.     DoInt &h33,MouseRegs%()        ' Set horizontal limits
  126.     MouseRegs%(Cx)=UpV%
  127.     MouseRegs%(Dx)=LowerV%
  128.     MouseRegs%(Ax)=8
  129.     DoInt &h33,MouseRegs%()        ' Set vertical limits
  130. End Sub
  131.  
  132.     ' Define the region to not display the mouse
  133.     ' UpH%=Upper left horizontal pos of region
  134.     ' UpV%=Upper left vertical    "  "    "
  135.     ' LowerH%=Lower right horizontal pos of region
  136.     ' LowerV%=Lower right vertical    "  "    "
  137.     '  NOTE: The coordinates of the region is in pixels, NOT character
  138.     '  coordinates. ROW=MousePosV/8+1, COL=MousePosH/8+1
  139.     '  MousePosV=(ROW-1)*8, MousePosH=(COL-1)*8
  140. Sub MouseRegion UpV%,UpH%,LowerV%,LowerH%
  141.     MouseRegs%(Cx)=UpH%
  142.     MouseRegs%(Dx)=UpV%
  143.     MouseRegs%(Si)=LowerH%
  144.     MouseRegs%(Di)=LowerH%
  145.     MouseRegs%(Ax)=16
  146.     DoInt &h33,MouseRegs%()
  147. End Sub
  148.  
  149.     ' ------------- End Of Mouse Functions -------------------
  150.  
  151.